#include <cstdio>
#include <cmath>

long long msqr( long long a )
{
    long long l = 0, r = ( 1 << 31 ) - 1, mid;
    while ( l < r )
    {
        mid = ( l + r ) / 2;
        if ( mid * mid < a )
            l = mid + 1;
        else
            r = mid;
    }
    if ( l * l != a )
        return l - 1;
    return l;
}

int main( )
{
    long long x, y, z, tx, ty, k, i, j, c, t;
    while ( scanf("%I64d", &k) && k )
    {
        c = 0;
        t = msqr( k );
        if ( t * t == k )
            if ( t % 2 )
                c += ( t - 1 ) / 2;
            else
                c += t / 2;
        if ( k == 4 ) c = 0;
        for ( z = 3; z < 32; z++ )
        {
            for ( x = 1; ; x++ )
            {
                tx = 1;
                for ( i = 0; i < z; i++ )
                    tx *= x;
                if ( tx >= k || tx * 2 >= k || tx * 2 + x * x * z >= k )
                    break;
                for ( y = x + 1; ; y++ )
                {
                    ty = 1;
                    for ( i = 0; i < z; i++ )
                        ty *= y;
                    if ( ty >= k || tx + ty >= k || tx + ty + x * y * z > k )
                        break;
                    if ( tx + ty + x * y * z == k )
                    {
                        c++;
                        break;
                    }
                }
            }
        }
        printf("%I64d\n", c);
    }
    return 0;
}
